package com.huang.juctool;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class CyclicBarrierDemo {
    public static void main(String[] args) throws BrokenBarrierException, InterruptedException {
        CyclicBarrier barrier = new CyclicBarrier(3,()->{

            System.out.println("可以召神龙了 。。。。");
        });

        for (int i = 0; i < 3; i++) {
            new Thread(()->{

                System.out.println("第"+Thread.currentThread().getName()+"条龙");
                try {
                    barrier.await();
                    System.out.println("第"+Thread.currentThread().getName()+"条龙2");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            },String.valueOf(i).toString()).start();

        }

    }
}
